'''
Created on 19/04/2010

@author: Mar
'''


class PCB:
    
    
    
    def __init__(self, aProgram):
        self.program = aProgram
        self.state = "Nuevo"
        self.pc = 0
        self.priority = aProgram.getPriority()
        self.totalQuantum = self.getTotalQuantum()
        
        
    def getPC(self):
        return self.pc
    
    def setPC(self, x):
        self.pc=x
    
    def totalInstructions(self):
        return (self.program.getInstructions().__len__())    
    
    
    def isThereNextInst(self):
        return (self.getPC()< self.totalInstructions())
    
    def getPriority(self):
        return self.priority
    
    def getProgram(self):
        return self.program
    
    def getCurrentInstruction(self):
        return self.getProgram().getInstructions().__getitem__(self.getPC())
    
    def getCurrentInstructionType(self):
        return self.getCurrentInstruction().getType()
    
    def toReady(self):
        self.state = "Ready"
    
    
    def advance(self):
        self.totalQuantum = self.totalQuantum - self.getCurrentInstruction().getTime()
        self.setPC(self.getPC() + 1)
        
    
    def toFinished(self):
        self.state = "finished"
        
    def isFinished(self):
        return (self.state == "finished")
    
    def getTotalQuantum(self):
        total = 0
        for inst in self.program.getInstructions():
            total = inst.getTime() + total
        return total

    
            
            
            
            
            
            
            
            
            